package com.manage.controller;

import com.beans.HouseInfo;
import com.beans.Neighborhood;
import com.beans.page.PageList;
import com.manage.util.UserUtils;
import com.services.HouseInfoService;
import com.services.NeighborhoodService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author jiangwei
 * @since 18/1/16
 */
@Controller
@RequestMapping("/release")
public class ReleaseController extends BaseController {

    @Autowired
    private HouseInfoService houseInfoService;
    @Autowired
    private NeighborhoodService neighborhoodService;

    /***
     * 查询列表(全部)
     *
     * @param houseInfo
     * @param request
     * @return
     */
    @RequiresPermissions("houseInfo:view")
    @RequestMapping(value = {"", "/", "list"})
    public String list(HouseInfo houseInfo, HttpServletRequest request) {
        List<Neighborhood> neighborhoodList = neighborhoodService.queryList(new Neighborhood());

        request.setAttribute("houseInfo", houseInfo);
        request.setAttribute("neighborhoodList", neighborhoodList);

        return "release/list";
    }


    /**
     * 异步获取list资源(全部)
     *
     * @param pageList
     * @param houseInfo
     * @return
     */
    @RequiresPermissions("houseInfo:view")
    @RequestMapping("asynList")
    @ResponseBody
    public PageList asynList(PageList pageList, HouseInfo houseInfo) {
        if (!UserUtils.getUser().isAdmin()) {//超级管理员，能够编辑所有房源
            houseInfo.setCreateBy(UserUtils.getUser().getUserId());
        }
        return houseInfoService.queryPageByHouseInfo(pageList, houseInfo);
    }
}
